package cn.iocoder.devlop.module.annual.report.forinvestment.controller.app;

import cn.iocoder.devlop.framework.common.pojo.CommonResult;
import cn.iocoder.devlop.module.annual.report.forinvestment.controller.vo.ForinvestmentOverwriteVO;
import cn.iocoder.devlop.module.annual.report.forinvestment.controller.vo.ForinvestmentRespVO;
import cn.iocoder.devlop.module.annual.report.forinvestment.convert.ForinvestmentConvert;
import cn.iocoder.devlop.module.annual.report.forinvestment.dal.dataobject.ForinvestmentDO;
import cn.iocoder.devlop.module.annual.report.forinvestment.service.ForinvestmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.devlop.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 企业年报对外投资信息")
@RestController
@RequestMapping("/annual/report/forinvestment")
@Validated
public class AppForinvestmentController {

    @Resource
    private ForinvestmentService forinvestmentService;


    @GetMapping("/list")
    @Operation(summary = "获得企业年报对外投资信息列表")
    public CommonResult<List<ForinvestmentRespVO>> getForinvestmentList(@RequestParam("regno") String regno, @RequestParam("ancheyear") String ancheyear) {
        List<ForinvestmentDO> list = forinvestmentService.getForinvestmentList(regno, ancheyear);
        return success(ForinvestmentConvert.INSTANCE.convertList(list));
    }

    @PutMapping("/overwrite")
    @Operation(summary = "覆盖更新企业年报对外投资信息列表")
    public CommonResult<Boolean> overwriteForinvestment(@Valid @RequestBody ForinvestmentOverwriteVO updateReqVO) {
        forinvestmentService.overwriteForinvestment(updateReqVO);
        return success(true);
    }

}
